//
//  ZXLSignTools.h
//  SignSecurityDemo
//
//  Created by zxl02 on 2020/8/14.
//  Copyright © 2020 CordovaDemo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZXLSecurityEnum.h"
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonHMAC.h>
#import <Security/Security.h>
#import "GTMBase64.h"
#import "ZXLSignData.h"
#import "ZXLConfig.h"

NS_ASSUME_NONNULL_BEGIN

#pragma mark - tools
@interface ZXLSignTools : NSObject
//解密
+(SignResult*)decryptionType:(SecurityEncryptType)encryptType decryptionStr:(NSString*)decryptionStr  zxlConfig:(ZXLConfig*)config;
//加密
+(SignResult*)encryptType:(SecurityEncryptType)encryptType StringToSign:(NSString*)StringToSign  zxlConfig:(ZXLConfig*)config;

/// md5 32位
/// @param srcString 加密字符串
/// @param isUppercase 大小写
+ (NSString *)getMd5_32Bit_String:(NSString *)srcString isUppercase:(BOOL)isUppercase;

/// md5 16位
/// @param srcString 加密字符串
/// @param isUppercase 大小写
+ (NSString *)getMd5_16Bit_String:(NSString *)srcString isUppercase:(BOOL)isUppercase;

/**
字符串SHA加密 String SHA1 encryption
@param string 要加密的字符串 String to be encrypted
@param shaType 要加密的类型  encrypte type
@param lowercase 是否小写 Is it a lowercase
@return 加密过的字符串 Encrypted string
*/
+ (NSString *)SHAEncryptWithString:(NSString *)string withType:(SecuritySignSHAEncryptType)shaType withLowercase:(BOOL)lowercase;

/// 字典排序 返回:key=value&key=value
/// @param params 字典
+ (NSString *)getStringWithDic:(NSMutableDictionary*)params;

/// 获取字典排序后的key或者value
/// @param obj 字典
/// @param dataType 数据类型
/// @param securityResult 降 升序
+(NSString *)getNeedSignStrFrom:(id)obj dataType:(DictionaryType)dataType securityResult:(SecurityResult)securityResult;

/// 字典转字符串
/// @param dic 字典
+(NSString *)JSONString:(NSDictionary*)dic;

/// JSON字符串转成NSDictionary
/// @param jsonStr 字符串
+(NSDictionary *) dictionaryValue:(NSString*)jsonStr;

/// base64加密
/// @param string 字符串
+(NSString *)base64EncodeString:(NSString *)string;

/// base64解密
/// @param string 字符串
+(NSString *)base64DecodeString:(NSString *)string;

/// base86转data
/// @param string 字符串
+ (NSData *)base64DataFromString:(NSString *)string;

/**
 *  驼峰转下划线（loveYou -> love_you）
 */
+ (NSString *)underlineFromCamel:(NSString*)str;
/**
 *  下划线转驼峰（love_you -> loveYou）
 */
+ (NSString *)camelFromUnderline:(NSString*)str;
/**
 * 首字母变大写
 */
+ (NSString *)firstCharUpper:(NSString*)str;
/**
 * 首字母变小写
 */
+ (NSString *)firstCharLower:(NSString*)str;

+ (NSData *)UTF8DataWith:(NSData*)data;
@end


#pragma mark - AES
@interface ZXLSignToolAES : NSObject

/// AES 加密
/// @param plainText  加密字符串
/// @param key 秘钥
/// @param keySize 长度
+(NSString *)AESEncrypt:(NSString *)plainText key:(NSString *)key keySize:(SecuritySignLengthAES)keySize;

/// AES解密
/// @param encryptText 解密字符串
/// @param key 秘钥
/// @param keySize 长度
+(NSString *)AESDecrypt:(NSString *)encryptText key:(NSString *)key keySize:(SecuritySignLengthAES)keySize;
@end

#pragma mark - RSA
@interface ZXLSignToolRSA : NSObject

// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;
// return raw data
+ (NSData *)encryptData:(NSData *)data publicKey:(NSString *)pubKey;
// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str privateKey:(NSString *)privKey;
// return raw data
+ (NSData *)encryptData:(NSData *)data privateKey:(NSString *)privKey;

// decrypt base64 encoded string, convert result to string(not base64 encoded)
+ (NSString *)decryptString:(NSString *)str publicKey:(NSString *)pubKey;
+ (NSData *)decryptData:(NSData *)data publicKey:(NSString *)pubKey;
+ (NSString *)decryptString:(NSString *)str privateKey:(NSString *)privKey;
+ (NSData *)decryptData:(NSData *)data privateKey:(NSString *)privKey;

/// rsa加签
/// @param plainData 加签data
/// @param PrivatKey 私钥
+ (NSData *)sha256WithRSA:(NSData *)plainData  withPrivatKey:(NSString*)PrivatKey;

/// 验签
/// @param plainData 加密的data
/// @param signature 加签的data
/// @param publicKey 公钥
+ (BOOL)rsaSHA256VertifyingData:(NSData *)plainData withSignature:(NSData *)signature  withpublicKey:(NSString*)publicKey;
@end
#pragma mark - DES 3DES
@interface ZXLSignToolDES : NSObject
///DES加密
/// @param plainText 字符串
/// @param key key
+(NSString *)encryptUseDES:(NSString *)plainText key:(NSString *)key;
///DES解密
/// @param cipherText 字符串
/// @param key key
+(NSString *)decryptUseDES:(NSString *)cipherText key:(NSString *)key;
///3DES加密
/// @param plainText 字符串
/// @param key key
+(NSString *)encryptUse3DES:(NSString *)plainText key:(NSString *)key;
///3DES解密
/// @param cipherText 字符串
/// @param key key
+(NSString *)decryptUse3DES:(NSString *)cipherText key:(NSString *)key;
@end
NS_ASSUME_NONNULL_END
